#include <linux/module.h>
#include <linux/init.h>
#include <linux/cdev.h>
#include <linux/fs.h>

MODULE_LICENSE ("GPL");

//设备号
dev_t dev; 
unsigned int major = 0;
unsigned int minor = 10;

int __init led_drv_init (void)
{
	//dev = (major << 20) | minor;//自己实现
	//静态注册
	if (major) {
		dev = MKDEV (major, minor);
		register_chrdev_region (dev, 1, "leds");
	} else {
		//动态注册
		alloc_chrdev_region (&dev, minor, 1, "leds");
		major = MAJOR (dev);
		minor = MINOR (dev);
		printk (KERN_ERR "major = %d, minor = %d\n", major, minor);
	}
	return 0;
}
void __exit led_drv_exit (void)
{
	unregister_chrdev_region (dev, 1);
	return ;
}
module_init (led_drv_init);
module_exit (led_drv_exit);
